function request(path, options) {
    let method = options.method || 'GET';
    let baseUrl = "https://vip.join.ink/api"
    let data = options.data || {};
    let TOKEN = wx.getStorageSync('token');
    let is_shop = options.is_shop

    if (is_shop) {
        TOKEN = wx.getStorageSync('api_token');
    } else {
        TOKEN = wx.getStorageSync('token');
    }
    let header = {}
    if (TOKEN) {
        console.log("token 存在");
        //登录 定时过期
        let date_now = new Date()
        let c_date_user = wx.getStorageSync('c_date_user')
        let token_enadle = ((date_now - c_date_user) <604800000)


        console.log(token_enadle,"***********token_enadle**********");

        if (token_enadle) {
            console.log("token 有效");
            header = {
                'content-type': 'application/json',
                'X-Requested-With': 'XMLHttpRequest',
                'Authorization': "Bearer " + TOKEN
            }
        } else {
            header = {
                'content-type': 'application/json',
                'X-Requested-With': 'XMLHttpRequest',
                'Authorization': "",
            }
            console.log("token 失效");
            wx.removeStorageSync('token')
        }
    } else {
        console.log("token 不存在");
        header = {
            'content-type': 'application/json',
            'X-Requested-With': 'XMLHttpRequest',
            'Authorization': "",
        }
    }

    return new Promise((resolve, reject) => {
        wx.request({
            url: baseUrl + path,
            method: method,
            data: data,
            header,
            success: res => {
                let code = res.data.code
                let msg = res.data.msg
                if (code == 500 && msg == "无token认证!") {
                    console.log(code, msg, "请登录");

                    wx.showModal({
                        title: '未登录',
                        content: '您还没有登陆 是否前往登录',
                        showCancel: true,
                        cancelText: "取消",
                        confirmText: "登录",
                        confirmColor: '#dfb461',
                        success: function (res) {
                            if (res.cancel) {

                            } else {
                                wx.switchTab({
                                    url: '/pages/personal/personal',
                                })
                            }
                        }
                    })
                }
                // console.log(res, "请求成功");
                resolve(res)
            },
            fail: err => {
                console.log(err, "请求失败")
                reject(err)
            }
            
        });
    })
}




export default request;